﻿using WebFoundation;
using WebFoundation.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MHI.ScenarioManager.Interfaces
{
    /// <summary>
    /// Scenario,table entity: scenario
    /// </summary>
    public class Scenario : Entity<Guid>, IDataVersion, INotifyPropertyChanged,IName
    {
        public static string WorkFolderAppSettingCode = "FileRoot";
        public static string ScenarioFolderName = "Scenario";
        public static string TemplateFolderName = "Template";

        public static readonly string KeyId;
        public static readonly string KeyScenarioCode;
        public static readonly string KeyScenarioName;
        public static readonly string KeyModelType;
        public static readonly string KeyModelSubType;
        public static readonly string KeyTemplate;
        public static readonly string KeyInheritedScenario;
        public static readonly string KeyReadOnly;
        public static readonly string KeyEnabled;
        public static readonly string KeyRelativeFolder;
        public static readonly string KeyProjectFile;
        public static readonly string KeyCurrentTime;
        public static readonly string KeyStartTime;
        public static readonly string KeyEndTime;
        public static readonly string KeyCreateTime;
        public static readonly string KeyAutoCalculate;
        public static readonly string KeyModified;
        public static readonly string KeyChecked;
        public static readonly string KeyCalculated;
        //public static readonly string KeyVerified;
        public static readonly string KeyPublished;
        public static readonly string KeyOnlineFirst;
        public static readonly string KeyAutoAmend;
        public static readonly string KeyState;
        public static readonly string KeyDescription;
        public static readonly string KeyVersion;

        static Scenario()
        {
            KeyId = ExpressionHelper.GetPropertyName<Scenario>(r => r.Id);
            KeyScenarioCode = ExpressionHelper.GetPropertyName<Scenario>(r => r.ScenarioCode);
            KeyScenarioName = ExpressionHelper.GetPropertyName<Scenario>(r => r.ScenarioName);
            KeyModelType = ExpressionHelper.GetPropertyName<Scenario>(r => r.ModelType);
            KeyModelSubType = ExpressionHelper.GetPropertyName<Scenario>(r => r.ModelSubType);
            KeyTemplate = ExpressionHelper.GetPropertyName<Scenario>(r => r.Template);
            KeyInheritedScenario = ExpressionHelper.GetPropertyName<Scenario>(r => r.InheritedScenario);
            KeyReadOnly = ExpressionHelper.GetPropertyName<Scenario>(r => r.ReadOnly);
            KeyEnabled = ExpressionHelper.GetPropertyName<Scenario>(r => r.Enabled);
            KeyRelativeFolder = ExpressionHelper.GetPropertyName<Scenario>(r => r.RelativeFolder);
            KeyProjectFile = ExpressionHelper.GetPropertyName<Scenario>(r => r.ProjectFile);
            KeyCurrentTime = ExpressionHelper.GetPropertyName<Scenario>(r => r.CurrentTime);
            KeyStartTime = ExpressionHelper.GetPropertyName<Scenario>(r => r.StartTime);
            KeyEndTime = ExpressionHelper.GetPropertyName<Scenario>(r => r.EndTime);
            KeyCreateTime = ExpressionHelper.GetPropertyName<Scenario>(r => r.CreateTime);
            KeyAutoCalculate = ExpressionHelper.GetPropertyName<Scenario>(r => r.AutoCalculate);
            KeyModified = ExpressionHelper.GetPropertyName<Scenario>(r => r.Modified);
            KeyChecked = ExpressionHelper.GetPropertyName<Scenario>(r => r.Checked);
            KeyCalculated = ExpressionHelper.GetPropertyName<Scenario>(r => r.Calculated);
            //KeyVerified = ExpressionHelper.GetPropertyName<Scenario>(r => r.Verified);
            KeyPublished = ExpressionHelper.GetPropertyName<Scenario>(r => r.Published);
            KeyOnlineFirst = ExpressionHelper.GetPropertyName<Scenario>(r => r.OnlineFirst);
            KeyAutoAmend = ExpressionHelper.GetPropertyName<Scenario>(r => r.AutoAmend);
            KeyState = ExpressionHelper.GetPropertyName<Scenario>(r => r.State);
            KeyDescription = ExpressionHelper.GetPropertyName<Scenario>(r => r.Description);
            KeyVersion = ExpressionHelper.GetPropertyName<Scenario>(r => r.Version);
        }

        private Guid _id;
        private string _scenarioCode;
        private string _scenarioName;
        private string _modelType;
        private string _modelSubType;
        private int _template;
        private Guid _inheritedScenario;
        private int _readOnly;
        private int _enabled;
        private string _relativeFolder;
        private string _projectFile;
        private DateTime _currentTime = DateTime.Now;
        private DateTime _startTime = DateTime.Now;
        private DateTime _endTime = DateTime.Now;
        private DateTime _createTime = DateTime.Now;
        private int _autoCalculate;
        private int _modified;
        private int _checked;
        private int _calculated;
        //private int _verified;
        private int _published;
        private int _onlineFirst;
        private int _autoAmend;
        private string _state;
        private string _description;
        private Guid _version;

        /// <summary>
        /// Id , column: Id required
        /// </summary>
        [Required]
        public override Guid Id
        {
            get { return _id; }
            set
            {
                if (_id != value)
                {
                    _id = value;
                    NotifyOfChange(KeyId);
                }
            }
        }

        /// <summary>
        /// 方案代码 , column: code 
        /// </summary>
        [Required]
        [StringLength(100)]
        public string ScenarioCode
        {
            get { return _scenarioCode; }
            set
            {
                if (_scenarioCode != value)
                {
                    _scenarioCode = value;
                    NotifyOfChange(KeyScenarioCode);
                }
            }
        }

        /// <summary>
        /// 方案名称 , column: name 
        /// </summary>
        [StringLength(200)]
        public string ScenarioName
        {
            get { return _scenarioName; }
            set
            {
                if (_scenarioName != value)
                {
                    _scenarioName = value;
                    NotifyOfChange(KeyScenarioName);
                }
            }
        }

        /// <summary>
        /// 模型类型 , column: model_type 
        /// </summary>
        [StringLength(100)]
        public string ModelType
        {
            get { return _modelType; }
            set
            {
                if (_modelType != value)
                {
                    _modelType = value;
                    NotifyOfChange(KeyModelType);
                }
            }
        }

        /// <summary>
        /// 模型子类型 , column: model_subtype 
        /// </summary>
        [StringLength(200)]
        public string ModelSubType
        {
            get { return _modelSubType; }
            set
            {
                if (_modelSubType != value)
                {
                    _modelSubType = value;
                    NotifyOfChange(KeyModelSubType);
                }
            }
        }

        /// <summary>
        /// 是否为模板 , column: is_template 
        /// </summary>
        public int Template
        {
            get { return _template; }
            set
            {
                if (_template != value)
                {
                    _template = value;
                    NotifyOfChange(KeyTemplate);
                }
            }
        }

        /// <summary>
        /// 父方案 , column: inherited_scenario 
        /// </summary>
        public Guid InheritedScenario
        {
            get { return _inheritedScenario; }
            set
            {
                if (_inheritedScenario != value)
                {
                    _inheritedScenario = value;
                    NotifyOfChange(KeyInheritedScenario);
                }
            }
        }

        /// <summary>
        /// 是否只读 , column: read_only 
        /// </summary>
        public int ReadOnly
        {
            get { return _readOnly; }
            set
            {
                if (_readOnly != value)
                {
                    _readOnly = value;
                    NotifyOfChange(KeyReadOnly);
                }
            }
        }

        /// <summary>
        /// 是否可用 , column: enabled 
        /// </summary>
        public int Enabled
        {
            get { return _enabled; }
            set
            {
                if (_enabled != value)
                {
                    _enabled = value;
                    NotifyOfChange(KeyEnabled);
                }
            }
        }

        /// <summary>
        /// 相对路径 , column: relative_folder 
        /// </summary>
        [StringLength(1000)]
        public string RelativeFolder
        {
            get { return _relativeFolder; }
            set
            {
                if (_relativeFolder != value)
                {
                    _relativeFolder = value;
                    NotifyOfChange(KeyRelativeFolder);
                }
            }
        }

        /// <summary>
        /// 模型文件名称 , column: project_file 
        /// </summary>
        [StringLength(200)]
        public string ProjectFile
        {
            get { return _projectFile; }
            set
            {
                if (_projectFile != value)
                {
                    _projectFile = value;
                    NotifyOfChange(KeyProjectFile);
                }
            }
        }

        /// <summary>
        /// 当前时间 , column: currenttime 
        /// </summary>
        public DateTime CurrentTime
        {
            get { return _currentTime; }
            set
            {
                if (_currentTime != value)
                {
                    _currentTime = value;
                    NotifyOfChange(KeyCurrentTime);
                }
            }
        }

        /// <summary>
        /// 模型开始时间 , column: starttime 
        /// </summary>
        public DateTime StartTime
        {
            get { return _startTime; }
            set
            {
                if (_startTime != value)
                {
                    _startTime = value;
                    NotifyOfChange(KeyStartTime);
                }
            }
        }

        /// <summary>
        /// 模型结束时间 , column: endtime 
        /// </summary>
        public DateTime EndTime
        {
            get { return _endTime; }
            set
            {
                if (_endTime != value)
                {
                    _endTime = value;
                    NotifyOfChange(KeyEndTime);
                }
            }
        }

        /// <summary>
        /// 方案创建时间 , column: createtime 
        /// </summary>
        public DateTime CreateTime
        {
            get { return _createTime; }
            set
            {
                if (_createTime != value)
                {
                    _createTime = value;
                    NotifyOfChange(KeyCreateTime);
                }
            }
        }

        /// <summary>
        /// 是否自动计算 , column: auto_calculate 
        /// </summary>
        public int AutoCalculate
        {
            get { return _autoCalculate; }
            set
            {
                if (_autoCalculate != value)
                {
                    _autoCalculate = value;
                    NotifyOfChange(KeyAutoCalculate);
                }
            }
        }

        /// <summary>
        /// 是否修改 , column: modified 
        /// </summary>
        public int Modified
        {
            get { return _modified; }
            set
            {
                if (_modified != value)
                {
                    _modified = value;
                    NotifyOfChange(KeyModified);
                }
            }
        }

        /// <summary>
        /// 是否检查 , column: checked 
        /// </summary>
        public int Checked
        {
            get { return _checked; }
            set
            {
                if (_checked != value)
                {
                    _checked = value;
                    NotifyOfChange(KeyChecked);
                }
            }
        }

        /// <summary>
        /// 是否计算 , column: calculated 
        /// </summary>
        public int Calculated
        {
            get { return _calculated; }
            set
            {
                if (_calculated != value)
                {
                    _calculated = value;
                    NotifyOfChange(KeyCalculated);
                }
            }
        }

        ///// <summary>
        ///// 是否审核 , column: verified 
        ///// </summary>
        //public int Verified
        //{
        //    get { return _verified; }
        //    set
        //    {
        //        if (_verified != value)
        //        {
        //            _verified = value;
        //            NotifyOfChange(KeyVerified);
        //        }
        //    }
        //}

        /// <summary>
        /// 是否发布 , column: published 
        /// </summary>
        public int Published
        {
            get { return _published; }
            set
            {
                if (_published != value)
                {
                    _published = value;
                    NotifyOfChange(KeyPublished);
                }
            }
        }

        /// <summary>
        /// 是否在线优先 , column: online_first 
        /// </summary>
        public int OnlineFirst
        {
            get { return _onlineFirst; }
            set
            {
                if (_onlineFirst != value)
                {
                    _onlineFirst = value;
                    NotifyOfChange(KeyOnlineFirst);
                }
            }
        }

        /// <summary>
        /// 是否自动补齐 , column: auto_amend 
        /// </summary>
        public int AutoAmend
        {
            get { return _autoAmend; }
            set
            {
                if (_autoAmend != value)
                {
                    _autoAmend = value;
                    NotifyOfChange(KeyAutoAmend);
                }
            }
        }

        /// <summary>
        /// 方案状态 , column: state 
        /// </summary>
        [StringLength(200)]
        public string State
        {
            get { return _state; }
            set
            {
                if (_state != value)
                {
                    _state = value;
                    NotifyOfChange(KeyState);
                }
            }
        }

        /// <summary>
        /// 描述 , column: description 
        /// </summary>
        [StringLength(2000)]
        public string Description
        {
            get { return _description; }
            set
            {
                if (_description != value)
                {
                    _description = value;
                    NotifyOfChange(KeyDescription);
                }
            }
        }
        
        /// <summary>
        /// 版本 , column: version 
        /// </summary>
        public override Guid Version
        {
            get { return _version; }
            set
            {
                if (_version != value)
                {
                    _version = value;
                    NotifyOfChange(KeyVersion);
                }
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyOfChange(string propertyName)
        {
            if (this.PropertyChanged != null)
            {
                this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public string Name
        {
            get
            {
                return this.ScenarioCode;
            }
            set
            {
                this.ScenarioCode = value;
            }
        }
    }
}